package com.p2p.front.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.p2p.front.dal.dao.LoanPhotoDao;
import com.p2p.front.dal.model.LoanPhoto;
import com.p2p.front.service.LoanPhotoService;

@Service("loanPhotoService")
public class LoanPhotoServiceImpl implements LoanPhotoService {

	@Resource
	LoanPhotoDao loanPhotoDao;

	@Override
	public void save(LoanPhoto loanPhoto) {
		// TODO Auto-generated method stub
		loanPhotoDao.save(loanPhoto);
	}

	@Override
	public List<LoanPhoto> findByLid(Long lid) {
		// TODO Auto-generated method stub
		return loanPhotoDao.findByLid(lid);
	}
	
	@Override
	public List<LoanPhoto> findByLidAndType(Long lid,Integer type) {
		// TODO Auto-generated method stub
		return loanPhotoDao.findByLidAndType(lid,type);
	}

	/*@Override
	public Map<Long, List<LoanPhoto>> findByLidList(List<Long> lidList) {
		Map<Long, List<LoanPhoto>> map = new HashMap<Long, List<LoanPhoto>>();
		List<LoanPhoto> list = loanPhotoDao.findByLidList(lidList);
		for (LoanPhoto loanPhoto : list) {
			Long lid = loanPhoto.getLid();
			List<LoanPhoto> photolist = map.get(lid);
			if (photolist == null) {
				photolist = new ArrayList<LoanPhoto>();
				map.put(lid, photolist);
			}
			photolist.add(loanPhoto);
		}
		return map;
	}*/
	
	//@Override
	public Map<Long, List<LoanPhoto>> findByLidListAndType(List<Long> lidList,Integer type) {
		Map<Long, List<LoanPhoto>> map = new HashMap<Long, List<LoanPhoto>>();
		List<LoanPhoto> list = loanPhotoDao.findByLidListAndType(lidList,type);
		for (LoanPhoto loanPhoto : list) {
			Long lid = loanPhoto.getLid();
			List<LoanPhoto> photolist = map.get(lid);
			if (photolist == null) {
				photolist = new ArrayList<LoanPhoto>();
				map.put(lid, photolist);
			}
			photolist.add(loanPhoto);
		}
		return map;
	}

	/*@Override
	public List<LoanPhoto> findByLidList(Long... ids) {
		return loanPhotoDao.findByLidList(Arrays.asList(ids));
	}*/

	@Override
	public Map<Long, List<LoanPhoto>> findLoanPhotoList() {
		Map<Long, List<LoanPhoto>> map = new HashMap<Long, List<LoanPhoto>>();
		List<LoanPhoto> list = loanPhotoDao.findList();
		for (LoanPhoto loanPhoto : list) {
			Long lid = loanPhoto.getLid();
			List<LoanPhoto> photolist = map.get(lid);
			if (photolist == null) {
				photolist = new ArrayList<LoanPhoto>();
				map.put(lid, photolist);
			}
			photolist.add(loanPhoto);
		}
		return map;
	}

	@Override
	public LoanPhoto findById(Long id) {
		// TODO Auto-generated method stub
		return loanPhotoDao.findById(id);
	}

	@Override
	public void deleteById(Long id) {
		loanPhotoDao.deleteById(id);
	}

	@Override
	public void updateImageStatus(Long id, int status) {
		loanPhotoDao.updateImageStatus(id, status);
	}

}
